import time
from multiprocessing import Pool
import os


def worker(num):
    for i in range(num):
        print(f"进程ID: {os.getpid()}, 进度: {i + 1}/{num}")
        time.sleep(1)
    return f"任务 {num} 完成"


def callback(result):
    print(f"回调通知: {result}")


def error_callback(e):
    print(f"任务出错: {str(e)}")


if __name__ == '__main__':
    pool = Pool(3)

    for i in range(1, 10):
        print(f"-----提交任务 {i}----")
        pool.apply_async(
            worker,
            args=(i,),
            callback=callback,
            error_callback=error_callback
        )

    pool.close()
    pool.join()
